const {ipcRenderer} = require('electron')
console.log(ipcRenderer)
const account = "0b08fcf0ad3eae8620ea56e0daa457ef";
const token = "3e499d61c7de1fdfa7f5cf76c8be568f"
/**
 * SDK连接 功能相关
 */
var nim = NIM.getInstance({
    //控制台日志，上线时应该关掉
    //debug: true || { api: 'info', style: 'font-size:14px;color:blue;background-color:rgba(0,0,0,0.1)' },
    appKey: "4b024821f348f78566c75dea9b0b285e",
    account: account,
    token: token,
    //链接成功
    onconnect: onConnect,
    // //收到消息
    onmsg: onMsg,
    //用户名片
    onmyinfo: onMyInfo,

    // //同步
    // onsyncdone:onSyncDone,
    // //漫游消息
    onroamingmsgs:onRoamingMsgs,
    // //离线消息
    onofflinemsgs: onOfflineMsgs,
    // //错误信息
    // onerror: onError,
    // //当前登录帐号在其它端的状态发生改变了
    // onloginportschange: onLoginPortsChange,
    // syncTeamMembers: false,//全成员先不同步了
    // //此时说明 `SDK` 已经断开连接, 请开发者在界面上提示用户连接已断开, 而且正在重新建立连接
    // onwillreconnect: onWillReconnect,
    // //链接断开
    // ondisconnect: onDisconnect,
    // //用户关系
    // onblacklist: onBlacklist,
    // //好友列表
    // onfriends: onFriends,

    // //名片更新
    // onupdatemyinfo: onUpdateMyInfo,
    // onusers: onUsers,
    // onupdateuser: onUpdateUser,
    // onrobots: onRobots,
    // //群
    // onteams: onTeams,
    // onsynccreateteam: onCreateTeam,
    // onteammembers: onTeamMembers,
    // onupdateteammember: onUpdateTeamMember,
    // //会话
    // onsessions: onSessions,
    // onupdatesession: onUpdateSession,
    // //漫游
    // onroamingmsgs: onRoamingMsgs,
    // //离线消息
    // onofflinemsgs: onOfflineMsgs,


});
function onConnect(data) {
    console.log(data,"链接成功")
}
function onMsg(msg) {
    console.log('收到消息', msg);
    ipcRenderer.send('electron-onMsg', msg)
}
function onMyInfo(msg){
    console.log(msg,"收到我的名片")
    ipcRenderer.send("electron-onMyInfo",msg)
}

function onSyncDone(data) {
    console.log('同步完成',data);
}
function onRoamingMsgs(obj) {
    console.log('收到漫游消息', obj);
}
function onOfflineMsgs(obj) {
    console.log('收到离线消息', obj);
}

function onError(err,data){
    console.log(err,data,"错误信息")
}
function onDisconnect(msg){
    console.log(msg,"此时说明 `SDK` 处于断开状态，开发者此时应该根据错误码提示相应的错误信息，并且跳转到登录页面")
}
function onLoginPortsChange(loginPorts){
    console.log('当前登录帐号在其它端的状态发生改变了', loginPorts);
}
function onTeams(msg){
    console.log(msg,"群列表")
}
function onWillReconnect(msg){
    console.log(msg,"此时说明 `SDK` 已经断开连接, 请开发者在界面上提示用户连接已断开, 而且正在重新建立连接")
}
function onBlacklist(msg){
    console.log(msg,"收到黑名单")
}
function onFriends(msg){
    console.log(msg,"好友列表")
}

function onUpdateMyInfo(msg){
    console.log(msg,"我的名片更新")
}
function onUsers(msg){
    console.log('收到用户名片列表', msg);
}
function onUpdateUser(msg){
    console.log(msg,"用户名片更新")
}
function onRobots(msg){
    console.log(msg,"收到机器人列表")
}
function onCreateTeam(msg){
    console.log(msg,"建群回调")
}
function onTeamMembers(teamId, members){
    console.log('群id', teamId, '群成员', members);
}
function onUpdateTeamMember(teamMember) {
    console.log('群成员信息更新了', teamMember);

}
function onSessions(sessions) {
    console.log('收到会话列表--最近会话列表', sessions);

}
function onUpdateSession(session) {
    console.log('会话更新了', session);
}
function onRoamingMsgs(obj) {
    console.log('漫游消息', obj);
}
function onOfflineMsgs(obj) {
    console.log('离线消息', obj);

    // ipcRenderer.send("electron-onOfflineMsgs",{a:1,b: "haha"})

}

ipcRenderer.on('fn2', function(event, arg) {
    console.log(arg); // prints "pong"
});